package com.yearner.reviewplan.common.model;

import com.yearner.reviewplan.common.util.StringUtils;
import com.yearner.reviewplan.user.model.UserId;
import lombok.Getter;
import lombok.Setter;

/**
 * @author pengyg
 * @since 2020/1/8
 */
@Getter
@Setter
public class Token {
    private String userId;
    private String token;
    private String username;

    public Token() {

    }

    public Token(String userId, String token) {
        this.userId = userId;
        this.token = token;
    }
    public Token(String userId, String token,String username) {
        this.userId = userId;
        this.token = token;
        this.username = username;
    }
    public static Token of(String userId, String token) {
        return new Token(userId, token);
    }
    public static Token of(UserId userId, String token) {
        return new Token(userId.toString(), token);
    }
    public static Token of(UserId userId, String token,String username) {
        return new Token(userId.toString(), token,username);
    }

    @Override
    public int hashCode() {
        return userId.hashCode()+token.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof Token) {
            Token argObj = (Token) obj;
            return StringUtils.isNotBlank(this.userId, argObj.userId) && this.userId.equals(argObj.userId)
                    && StringUtils.isNotBlank(this.token, argObj.token) && this.token.equals(argObj.token);
        }
        return super.equals(obj);
    }
}
